package com.aerospace.example.helloworld;

import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;

/**
 * @ClassName HelloClient
 * @Description
 * @Author yuhang11
 * @Date 2021/7/12 4:41 下午
 * @Version 1.0
 */
public class HelloClient {
    public static void main(String[] args) {
        //建立channel，线程安全，可重用
        ManagedChannel channel = ManagedChannelBuilder.forTarget("localhost:50051").usePlaintext().build();
        try{
            //请求
            simpleRequest(channel);
            serverStreamRequest();

        }catch (Exception e){
            e.printStackTrace();
        }
    }

    private static void simpleRequest(ManagedChannel channel) {
        //定义同步阻塞的stub
        GreeterGrpc.GreeterBlockingStub blockingStub = GreeterGrpc.newBlockingStub(channel);
        HelloRequest helloRequest = HelloRequest.newBuilder().setName("liuyuhang").build();
        HelloReply helloReply = blockingStub.simpleHello(helloRequest);
        System.out.println(helloReply.getMessage());
    }
}
